package project.youkumenu.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import project.youkumenu.R;
import project.youkumenu.base.BaseApp;
import project.youkumenu.utils.DensityUtil;
import project.youkumenu.utils.LogUtil;


/**
 * Created by lgs on 2018/1/25.
 */

public class CustomView extends View {

    public static final int DENSITY = (int) BaseApp.getBaseAppContext().getResources().getDisplayMetrics().density;
//    public static final int DENSITY =

    private static final int LEFT_TITLE_LEFT_BTN_WIDTH = 30 * DENSITY; //左标题左边按钮的宽度
    private static final int LEFT_TITLE_CONTENT_WIDTH = 60 * DENSITY;//左标题中间文字的宽度
    private static final int LEFT_TITLE_RIGHT_BTN_WIDTH = 30 * DENSITY;//左标题右边按钮的宽度
    private static final int RIGHT_TITLE_CONTENT_WIDTH = 30 * DENSITY;//右标题内容文字的宽度
    private static final int RIGHT_TITLE_RIGHT_BTN_WIDTH = 20 * DENSITY;//右标题右边按钮的宽度

    private static final String TAG = "CustomView3";
    private float width;
    private CallBackLunarCalendar callBackLunarCalendar;//设置此接口后，农历显示就会正常
    private float matrixWidth;//矩阵单个宽度
    private static final float HEIGHT_B_WIDTH = 1.0f;//高度和宽度的比
    private float paddingLeft;  //视图padding
    private float paddingTop;
    private float paddingRight;
    private float paddingBottom;
    private int currentYear;    //当前系统年份
    private int currentMonth;   //当前系统月份
    private int currentDay; //当前系统日期
    public Calendar calendar;//日历
    private Paint paint;//画笔
    private float titleHeight;//title高度
    private String titleRightText = "水质巡塘";//title右边文字
    private float tightRightTextSize;//title右边文字大小
    private static final String TITLE_RIGHT_TEXT_COLOR = "#666666"; //title右边文字颜色
    private float strokeWidth;//title下方分割线宽度
    private static final String STROKE_COLOR = "#d2d2d2";//title下方分割线颜色
    private String[] weeks = {"日", "一", "二", "三", "四", "五", "六"};
    private float weekTitleHeight;//周标题高度
    public static final String WEEK_TITLE_TEXT_COLOR = "#999999";//周标题颜色

    private List<WeekMatrixPoint> weekMatrixPoints;//周矩阵点集
    private List<Integer> listGreenRound;//有绿色小圆点的日期集合
    Paint paintGR = new Paint(Paint.ANTI_ALIAS_FLAG);//绿色圆点画笔，抗锯齿
    Paint paintOk = new Paint();//小对勾画笔

    {
        weekMatrixPoints = new ArrayList<>();
        listGreenRound = new ArrayList<>();
        calendar = Calendar.getInstance();
        paint = new Paint();
        titleHeight = getResources().getDimension(R.dimen.calendar_title_height);
        tightRightTextSize = getResources().getDimension(R.dimen.calendar_title_right_text_size);
        weekTitleHeight = getResources().getDimension(R.dimen.calendar_week_title_height);
        strokeWidth = getResources().getDimension(R.dimen.calendar_stroke_width);

        paintOk.setColor(Color.WHITE);
        paintOk.setTextSize(getResources().getDimension(R.dimen.txt_size_10sp));
        paintOk.setTextAlign(Paint.Align.CENTER);
        paintGR.setColor(Color.GREEN);
        paintGR.setStrokeCap(Paint.Cap.ROUND);//设置画笔圆点
        paintGR.setStrokeWidth(getResources().getDimension(R.dimen.calendar_point_r));
        //        setCalendar(2018, 0, getTestRoundList());
    }

    //测试阶段使用，自定义视图完成后即可删除 （模拟生成勾选点集合）
    public List<Integer> getTestRoundList() {
        List<Integer> list = new ArrayList<>();
       /* list.add(1);
        list.add(3);
        list.add(5);
        list.add(7);
        list.add(18);
        list.add(20);
        list.add(23);
        list.add(24);*/
        return list;
    }

    public void setListGreenRound(List<Integer> listGreenRound) {
        this.listGreenRound = listGreenRound;
    }

    public CustomView(Context context) {
        super(context);
    }


    public CustomView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setTitleRightText(String titleRightText) {
        this.titleRightText = titleRightText;
        postInvalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawTitle(canvas, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH));//绘制标题栏
        paint.setColor(Color.parseColor(STROKE_COLOR));
        canvas.drawLine(0, titleHeight, width, titleHeight, paint);
        drawWeekTitle(canvas);//绘制周标题
        initWeekMatrixPoints();//初始化矩阵点集合
        drawWeekMatrixPoints(canvas);//绘制矩阵集合
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        //margin表示控件边缘相对父控件的边距
        //padding表示控件的内容相对控件的边缘的边距
        paddingLeft = getPaddingLeft();
        paddingTop = getPaddingTop();
        paddingRight = getPaddingRight();
        paddingBottom = getPaddingBottom();
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (null != layoutParams) {
            //-1 为match_parent , -2 为 wrap_content ，将wrap_content统一作为match_parent处理
            if (layoutParams.width == -1 || layoutParams.width == -2) {
                //match_parent
                float parentWidth = getViewParentWidth(getParent());
                //使用DisplayMetrics获取屏幕参数
                //只有activity可以使用WindowManager，否则应该使用Context.getResources().getDisplayMetrics()来获取。
                //Activity中设置DM：
                //Context.getResources().getDisplayMetrics()依赖于手机系统，获取到的是系统的屏幕信息；
                //WindowManager.getDefaultDisplay().getMetrics(dm)是获取到Activity的实际屏幕信息。
                width = parentWidth == -3 ? getResources().getDisplayMetrics().widthPixels : parentWidth;
            } else {
                width = layoutParams.width;
            }
        }
        width = width - DensityUtil.dp2px(40);
        matrixWidth = (width - paddingLeft - paddingRight) / 7;

        setMeasuredDimension((int) width, (int) getViewHeight());   //控制最终视图的大小
    }

    //计算并返回屏幕的高度
    private float getViewHeight() {
        //视图高度应该为 矩阵所占高度 + 标题所占高度 + 分割线线宽 + 周标题宽度 + 屏幕底部padding
        return matrixWidth * HEIGHT_B_WIDTH * getCurrentMonthMaxWeeks() + titleHeight + strokeWidth + weekTitleHeight + paddingBottom;
    }

    //获取当前月的最大周数
    private int getCurrentMonthMaxWeeks() {
        int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//获取当月最后一天
        calendar.set(Calendar.DAY_OF_MONTH, actualMaximum);//时间设置为最后一天
        return calendar.get(Calendar.WEEK_OF_MONTH);//最后一天所在的周数就是当月总周数
    }

    //获取父控件高度，一直向上找， -3即为窗口
    private float getViewParentWidth(ViewParent parent) {
        if (parent instanceof ViewGroup) {
            ViewGroup.LayoutParams layoutParams = ((ViewGroup) parent).getLayoutParams();
            if (layoutParams.width == -1 || layoutParams.width == -2) {
                return getViewParentWidth(parent.getParent());
            } else {
                return ((ViewGroup) parent).getWidth();
            }
        }
        return -3;
    }
    public void setCalendarTitle(int year, int month){
        calendar.set(Calendar.DAY_OF_MONTH, 1);//之所以把当月天数初始化为1，是为了防止calendar当前天数大于修改后月份的最大天数，而导致的月份后移
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.YEAR, year);
    }

    public void setCalendar(List<Integer> listGreenRound) {
//        if (year < 1970) {
//            Log.i(TAG, "setCalendar: 1970年之前的年份无效 ");
//            return;
//        }
//        if (month < 0 || month > 11) {
//            Log.i(TAG, "setCalendar: 月份参数应该在 0 - 11 之间 0 表示1月 依次类推");
//            return;
//        }
        if (null != calendar) {
//            this.listGreenRound.clear();
            if (null != listGreenRound) {
                LogUtil.i("接收数据中的大小：" + listGreenRound.size());
                this.listGreenRound.addAll(listGreenRound);
            }

        }
        //设置完Calendar之后需要动态的改变控件的高度
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (null != layoutParams) {
            layoutParams.height = (int) getViewHeight();
            setLayoutParams(layoutParams);
        }
        LogUtil.i("内容重绘中的listGreenRound：" + this.listGreenRound.size());
        invalidate();//内容重绘
    }

    //绘制周矩阵
    private void drawWeekMatrixPoints(Canvas canvas) {
        int year = calendar.get(Calendar.YEAR);//显示年
        int month = calendar.get(Calendar.MONTH);//显示月
        boolean flag = currentYear == year && currentMonth == month; //显示年月是否为本年本月
        calendar.set(Calendar.DAY_OF_MONTH, 1);//设置为本月第一天
        int nullDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;//得到第一天为一周中的第几天
        int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//获取当月最后一天
        paint.setColor(Color.parseColor("#333333"));//设置画笔颜色
        paint.setTextAlign(Paint.Align.CENTER);//设置画笔绘制文字水平居中
        Paint paintNl = new Paint();//农历画笔
        float nLTextSize = getResources().getDimension(R.dimen.txt_size_10sp);//农历字体大小
        paintNl.setTextSize(nLTextSize);
        paintNl.setColor(Color.parseColor("#666666"));  //设置农历画笔颜色
        paintNl.setTextAlign(Paint.Align.CENTER);
        for (int i = 0; i < weekMatrixPoints.size(); i++) {
            if (i - nullDay >= 0 && i - nullDay < actualMaximum) {
                //为当前天数添加圆标记
                if (flag && i - nullDay + 1 == currentDay) {
                    Paint paint = new Paint();//为了不影响其他的字体，为今日圆圈设置了单独的画笔，此画笔可以拿出来放到代码块中初始化
                    paint.setColor(Color.RED);
                    paint.setAntiAlias(true);
                    paint.setStyle(Paint.Style.STROKE);
                    paint.setStrokeWidth(strokeWidth);
                    canvas.drawCircle(weekMatrixPoints.get(i).x, weekMatrixPoints.get(i).y, weekMatrixPoints.get(i).shortR, paint);
                }
                weekMatrixPoints.get(i).year = year;
                weekMatrixPoints.get(i).month = month;
                weekMatrixPoints.get(i).day = i - nullDay + 1;
                canvas.drawText("" + weekMatrixPoints.get(i).day, weekMatrixPoints.get(i).x, weekMatrixPoints.get(i).y, paint);//绘制时间
                canvas.drawText(null == callBackLunarCalendar ? "农历" : callBackLunarCalendar.callBackLunarCalendar(year, month, i - nullDay + 1), weekMatrixPoints.get(i).x, weekMatrixPoints.get(i).y + nLTextSize, paintNl);//农历自己找一个根据日期转换农历的代码，网上有很多替换掉就行了，位置微调自己控制

                //绘制绿色圆点和对勾
                if (null != listGreenRound && listGreenRound.contains(i - nullDay + 1)) {
                    canvas.drawPoint(weekMatrixPoints.get(i).x + weekMatrixPoints.get(i).shortR * 0.6f, weekMatrixPoints.get(i).y - weekMatrixPoints.get(i).shortR * 0.6f, paintGR);
                    canvas.drawText("✓", weekMatrixPoints.get(i).x + weekMatrixPoints.get(i).shortR * 0.6f, weekMatrixPoints.get(i).y - weekMatrixPoints.get(i).shortR * 0.5f, paintOk);
                }

                weekMatrixPoints.get(i).isListener = true;
            } else {
                weekMatrixPoints.get(i).isListener = false;
            }
        }
    }

    /**
     * 绘制周标题
     *
     * @param canvas 画布
     */
    private void drawWeekTitle(Canvas canvas) {
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setTextSize(weekTitleHeight / 2);
        paint.setColor(Color.parseColor(WEEK_TITLE_TEXT_COLOR));
        for (int i = 0; i < 7; i++) {
            canvas.drawText(weeks[i], paddingLeft + i * matrixWidth + matrixWidth / 2, titleHeight + strokeWidth + (weekTitleHeight / 4) * 3, paint);
        }
    }

    /**
     * zcy
     * 绘制title
     *
     * @param canvas 画布
     * @param year   年
     * @param month  月
     */
    private void drawTitle(Canvas canvas, int year, int month) {
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setTextSize(getResources().getDimension(R.dimen.txt_size_12sp));
        paint.setColor(Color.parseColor(TITLE_RIGHT_TEXT_COLOR));
        //左标题默认占的视图宽度
        canvas.drawText("<", paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH / 2, (titleHeight / 4) * 3, paint);
        canvas.drawText(+year + "年" + (month + 1) + "月", paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH + LEFT_TITLE_CONTENT_WIDTH / 2, (titleHeight / 4) * 3, paint);
        canvas.drawText(">", paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH + LEFT_TITLE_CONTENT_WIDTH + LEFT_TITLE_RIGHT_BTN_WIDTH / 2, (titleHeight / 4) * 3, paint);

        paint.setColor(Color.parseColor(TITLE_RIGHT_TEXT_COLOR));
        paint.setTextSize(tightRightTextSize);
        paint.setTextAlign(Paint.Align.RIGHT);
        canvas.drawText(" ﹀", width - paddingRight - RIGHT_TITLE_RIGHT_BTN_WIDTH / 2, (titleHeight / 4) * 3, paint);
        canvas.drawText(titleRightText, width - paddingRight - RIGHT_TITLE_RIGHT_BTN_WIDTH - RIGHT_TITLE_CONTENT_WIDTH / 2, (titleHeight / 4) * 3, paint);
    }

    /**
     * zcy
     * 初始化矩阵点集合
     */
    private void initWeekMatrixPoints() {
        //获取一个新的Calendar 得到系统当前年月日，更新数据
        Calendar calendar = Calendar.getInstance();
        currentYear = calendar.get(Calendar.YEAR);
        currentMonth = calendar.get(Calendar.MONTH);
        currentDay = calendar.get(Calendar.DAY_OF_MONTH);
        //原有矩阵点数据清空
        int preSize = weekMatrixPoints.size();//之前的size
        for (WeekMatrixPoint point : weekMatrixPoints) {
            point.clear();
        }
        int maxWeek = getCurrentMonthMaxWeeks();
        float startY = titleHeight + strokeWidth + weekTitleHeight;//内容开始的纵坐标
        float matrixHeight = matrixWidth * HEIGHT_B_WIDTH;
        float min = Math.min(matrixWidth, matrixHeight);
        //矩阵点数量不足，创建新的(缺多少创建多少)
        for (int i = 0; i < maxWeek * 7 - preSize; i++) {
            weekMatrixPoints.add(new WeekMatrixPoint(0, 0, 0));
        }
        //初始化有效矩阵点的数据
        for (int iy = 0; iy < maxWeek; iy++) {
            for (int ix = 0; ix < 7; ix++) {
                WeekMatrixPoint point = weekMatrixPoints.get(iy * 7 + ix);
                point.x = paddingLeft + ix * matrixWidth + matrixWidth / 2;
                point.y = startY + iy * matrixHeight + matrixHeight / 2;
                point.shortR = min / 2; //此处被修改为由2变为3
            }
        }
    }

     /*
    * -----------------------  此处为触摸事件的简单处理，如果你想要更丰富的事件响应，请注释掉这一块，自己重写  start -------------------------------
    * */

    private float onTouchEventX;
    private float onTouchEventY;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                //记录按下坐标
                onTouchEventX = event.getX();
                onTouchEventY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                float lengthX = event.getX() - onTouchEventX;
                float lengthY = event.getY() - onTouchEventY;
                if (Math.abs(lengthX) > Math.abs(lengthY) && Math.abs(lengthX) > getWidth() / 3) {
                    //横向移动的距离比纵向移动的距离大，并且滑动超过三分之一屏幕的时候，默认为大滑动事件,直接响应
                    return true;
                }
                //不是横向大滑动事件，走到这里就按照点击事件处理
                click(onTouchEventX, onTouchEventY, event.getX(), event.getY());
                return true;
        }
        //        return super.onTouchEvent(event);
        return true;//自己处理触摸事件
    }

    /**
     * 特殊触摸事件的处理
     * zcy
     *
     * @param downX 按下的X坐标
     * @param downY 按下的Y坐标
     * @param upX   抬起的X坐标
     * @param upY   抬起的Y坐标
     */
    private void click(float downX, float downY, float upX, float upY) {
        if (downY <= titleHeight && upY <= titleHeight) {
            //此情况都默认点击在头部
            //头部分成左三分之一，空白，右四分之一
            if (downX <= paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH + LEFT_TITLE_CONTENT_WIDTH + LEFT_TITLE_RIGHT_BTN_WIDTH
                    && upX <= paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH + LEFT_TITLE_CONTENT_WIDTH + LEFT_TITLE_RIGHT_BTN_WIDTH) {
                //事件在左边范围
                if (downX < paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH && upX < paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH) {
                    //减一月
                    if (null != onTouchListener) {
                        onTouchListener.onClickTitle(OnTouchListener.CLICK_REDUCE_MONTH);
                    }
                } else if (downX > paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH + LEFT_TITLE_CONTENT_WIDTH
                        && upX > paddingLeft + LEFT_TITLE_LEFT_BTN_WIDTH + LEFT_TITLE_CONTENT_WIDTH) {
                    //加一月
                    if (null != onTouchListener) {
                        onTouchListener.onClickTitle(OnTouchListener.CLICK_ADD_MONTH);
                    }
                } else {
                    //选择时间
                    if (null != onTouchListener) {
                        onTouchListener.onClickTitle(OnTouchListener.CLICK_SELECT_YEAR_AND_MONTH);
                    }
                }
                return;
            }
            if (downX >= width - RIGHT_TITLE_CONTENT_WIDTH - RIGHT_TITLE_RIGHT_BTN_WIDTH - paddingRight
                    && upX >= width - RIGHT_TITLE_CONTENT_WIDTH - RIGHT_TITLE_RIGHT_BTN_WIDTH - paddingRight) {
                if (null != onTouchListener) {
                    onTouchListener.onClickTitle(OnTouchListener.CLICK_RIGHT);
                }
                return;
            }
            return;
        }
        WeekMatrixPoint weekMatrixPoint = null;//最后一个有效矩阵点
        int size = weekMatrixPoints.size();
        for (int i = size; i > 0; i--) {
            WeekMatrixPoint point = weekMatrixPoints.get(i - 1);
            if (point.shortR > 0) {
                weekMatrixPoint = point;
                break;
            }
        }
        if (downY > titleHeight + strokeWidth + weekTitleHeight
                && upY > titleHeight + strokeWidth + weekTitleHeight
                && null != weekMatrixPoint
                && weekMatrixPoint.y + weekMatrixPoint.shortR >= downY
                && weekMatrixPoint.y + weekMatrixPoint.shortR >= upY) {
            //此情况默认点击在矩阵图部分
            for (int i = 0; i < weekMatrixPoints.size() / 7; i++) {
                WeekMatrixPoint pointH = weekMatrixPoints.get(i * 7);
                if (downY >= pointH.y - pointH.shortR
                        && upY >= pointH.y - pointH.shortR
                        && downY <= pointH.y + pointH.shortR
                        && upY <= pointH.y + pointH.shortR) {
                    //在此行
                    for (int j = 0; j < 7; j++) {
                        WeekMatrixPoint pointV = weekMatrixPoints.get(i * 7 + j);
                        if (downX >= pointV.x - pointV.shortR
                                && upX >= pointV.x - pointV.shortR
                                && downX <= pointV.x + pointV.shortR
                                && upX <= pointV.x + pointV.shortR) {
                            //在此列
                            if (pointV.isListener) {
                                if (null != onTouchListener) {
                                    onTouchListener.onClickDayMatrix(pointV.year, pointV.month, pointV.day);
                                }
                            } else {
                                Log.i(TAG, "click: 空白 ，没有触摸事件响应");
                            }
                            return;
                        }
                    }
                }
            }
        }
        //其余情况都在不需要处理的范围
    }

/*    private OnTouchListener listener = new OnTouchListener() {

        @Override
        public void onBigScrollH(boolean isLeftScroll) {
            Log.i(TAG, "onBigScrollH: " + (isLeftScroll ? "左滑" : "右滑"));
        }

        @Override
        public void onClickTitle(int onClickType) {
            switch (onClickType) {
                case CLICK_REDUCE_MONTH:
                    Log.i(TAG, "onClickTitle: 减少一月");
                    int jMonth = calendar.get(Calendar.MONTH) - 1;
                    int jYear = jMonth < 0 ? calendar.get(Calendar.YEAR) - 1 : calendar.get(Calendar.YEAR);
                    jMonth = jMonth < 0 ? jMonth + 12 : jMonth;
                    setCalendar(jYear, jMonth, getTestRoundList());
                    break;
                case CLICK_ADD_MONTH:
                    Log.i(TAG, "onClickTitle: 增加一月");
                    int addMonth = calendar.get(Calendar.MONTH) + 1;
                    int addYear = addMonth > 11 ? calendar.get(Calendar.YEAR) + 1 : calendar.get(Calendar.YEAR);
                    addMonth = addMonth > 11 ? addMonth - 12 : addMonth;
                    setCalendar(addYear, addMonth, getTestRoundList());
                    break;
                case CLICK_SELECT_YEAR_AND_MONTH:
                    Log.i(TAG, "onClickTitle: 选择年份");
                    Toast.makeText(getContext(), "请自己实现", Toast.LENGTH_SHORT).show();
                    break;
                case CLICK_RIGHT:
                    Log.i(TAG, "onClickTitle: 点击右边");
                    Toast.makeText(getContext(), "右边按钮点击了一下，可以自己实现点击事件监听", Toast.LENGTH_SHORT).show();
                    break;
            }
        }

        @Override
        public void onClickDayMatrix(int year, int month, int day) {
            Toast.makeText(getContext(), year + "年" + (month + 1) + "月" + day + "日\r\n 可以自己实现日期的点击事件", Toast.LENGTH_SHORT).show();
        }
    };*/

    public interface OnTouchListener {
        int CLICK_REDUCE_MONTH = 0;//减少一月
        int CLICK_ADD_MONTH = 1;//增加一月
        int CLICK_SELECT_YEAR_AND_MONTH = 2;//选择年份
        int CLICK_RIGHT = 3;//点击右边

        void onBigScrollH(boolean isLeftScroll);//参数true左滑，参数false右滑

        void onClickTitle(int onClickType);//点击类型

        void onClickDayMatrix(int year, int month, int day);//点击的是日期
    }

    private OnTouchListener onTouchListener;

    public void setOnTouchListener(OnTouchListener onTouchListener) {
        this.onTouchListener = onTouchListener;
    }

    /*
    * -----------------------  此处为触摸事件的简单处理，如果你想要更丰富的事件响应，请注释掉这一块，自己重写  end -------------------------------
    * */

    //单个日期矩阵点
    private class WeekMatrixPoint {
        float x;//X坐标
        float y;//Y坐标
        float shortR;//短半径
        boolean isListener;//是否应该有触摸事件 ，默认没有

        int year;
        int month;
        int day;

        WeekMatrixPoint(float x, float y, float shortR) {
            this.x = x;
            this.y = y;
            this.shortR = shortR;
        }

        void clear() {
            x = 0.0f;
            y = 0.0f;
            shortR = 0.0f;
            isListener = false;
            year = 0;
            month = 0;
            day = 0;
        }
    }

    public void setCallBackLunarCalendar(CallBackLunarCalendar callBackLunarCalendar) {
        this.callBackLunarCalendar = callBackLunarCalendar;
    }

    //获取农历的接口(参数需要年月日)
    public interface CallBackLunarCalendar {
        String callBackLunarCalendar(int year, int month, int day);
    }
}
